Imports System.Data.OleDb
Imports RIBS.Code.DBCode
Public Class SystemSetting

    ReadOnly Property AchiveLoop() As Int32
        Get
            Dim Conn As New OleDbConnection(gConnectionString)
            Dim Adapter As New OleDbDataAdapter
            Dim cmd As New OleDbCommand
            Dim dt As New DataTable
            Dim SQL As String = "Select * from SystemSettings Where Setting = 'AchiveLoopCount'"
            Adapter.SelectCommand = New OleDbCommand(SQL, Conn)
            Adapter.Fill(dt)
            If dt.Rows.Count > 0 Then
                Return CInt(dt.Rows(0).Item("SettingValue"))
            Else
                Return 20
            End If

        End Get

    End Property

    'ItemHistoryGrid

    Property HistoryColumns_Settings() As String
        Get
            Dim Conn As New OleDbConnection(gConnectionString)
            Dim Adapter As New OleDbDataAdapter
            Dim cmd As New OleDbCommand
            Dim dt As New DataTable
            Dim SQL As String = "Select * from SystemSettings Where Setting = 'HistoryColumns_Settings'"
            Adapter.SelectCommand = New OleDbCommand(SQL, Conn)
            Adapter.Fill(dt)
            If dt.Rows.Count > 0 Then
                Return dt.Rows(0).Item("SettingValue").ToString
            Else
                Dim Conn1 As New OleDbConnection(gConnectionString)
                Dim cmd1 As New OleDbCommand
                Conn1.Open()
                cmd1.Connection = Conn1
                SQL = "INSERT INTO SystemSettings ([Setting], SettingValue) VALUES ('HistoryColumns_Settings', ' ')"
                cmd1.CommandText = Sql
                cmd1.ExecuteNonQuery()
                Return " "
            End If

        End Get
        Set(ByVal value As String)
            Dim Conn1 As New OleDbConnection(gConnectionString)
            Dim cmd1 As New OleDbCommand
            Conn1.Open()
            cmd1.Connection = Conn1
            Dim Sql As String = "UPDATE SystemSettings SET SettingValue = '" & value & " '" & _
                                " WHERE Setting = 'HistoryColumns_Settings' "
            cmd1.CommandText = Sql
            cmd1.ExecuteNonQuery()
        End Set
    End Property

    Property HistoryColumns() As String
        Get
            Dim Conn As New OleDbConnection(gConnectionString)
            Dim Adapter As New OleDbDataAdapter
            Dim cmd As New OleDbCommand
            Dim dt As New DataTable
            Dim SQL As String = "Select * from SystemSettings Where Setting = 'HistoryColumns'"
            Adapter.SelectCommand = New OleDbCommand(SQL, Conn)
            Adapter.Fill(dt)
            If dt.Rows.Count > 0 Then
                Return dt.Rows(0).Item("SettingValue").ToString
            Else
                Return " "
            End If
        End Get
        Set(ByVal value As String)

        End Set
    End Property

    Property ImportTypes() As String
        Get
            Dim Conn As New OleDbConnection(gConnectionString)
            Dim Adapter As New OleDbDataAdapter
            Dim cmd As New OleDbCommand
            Dim dt As New DataTable
            Dim SQL As String = "Select * from SystemSettings Where Setting = 'OnlyImportTypes'"
            Adapter.SelectCommand = New OleDbCommand(SQL, Conn)
            Adapter.Fill(dt)
            If dt.Rows.Count > 0 Then
                Return dt.Rows(0).Item("SettingValue").ToString
            Else
                Return " "
            End If
        End Get
        Set(ByVal value As String)

        End Set
    End Property
    Property Actions() As String
        Get
            Try
                Dim Conn As New OleDbConnection(gConnectionString)
                Dim Adapter As New OleDbDataAdapter
                Dim cmd As New OleDbCommand
                Dim dt As New DataTable
                Dim SQL As String = "Select * from SystemSettings Where Setting = 'Actions'"
                Adapter.SelectCommand = New OleDbCommand(SQL, Conn)
                Adapter.Fill(dt)
                If dt.Rows.Count > 0 Then
                    Return dt.Rows(0).Item("SettingValue").ToString
                Else
                    Return " "
                End If

            Catch ex As Exception
                Throw ex
            End Try
            Return ""
        End Get
        Set(ByVal value As String)
            Try
                Dim Conn As New OleDbConnection(gConnectionString)
                Dim Adapter As New OleDbDataAdapter
                Dim cmd As New OleDbCommand
                Dim dt As New DataTable
                Dim SQL As String = "Select * from SystemSettings Where Setting = 'Actions'"
                Adapter.SelectCommand = New OleDbCommand(SQL, Conn)
                Adapter.Fill(dt)
                Conn.Open()
                cmd.Connection = Conn
                If dt.Rows.Count > 0 Then
                    SQL = "UPDATE SystemSettings SET SettingValue = '" & value & "' WHERE [Setting]= 'Actions' "
                Else
                    SQL = "INSERT INTO SystemSettings ([Setting], SettingValue) VALUES ('Actions', '" & value & "')"
                End If

                cmd.CommandText = SQL
                cmd.ExecuteNonQuery()
                Conn.Close()
            Catch ex As Exception
                Throw ex
            End Try
        End Set
    End Property

    Property TaskActions() As String
        Get
            Try
                Dim Conn As New OleDbConnection(gConnectionString)
                Dim Adapter As New OleDbDataAdapter
                Dim cmd As New OleDbCommand
                Dim dt As New DataTable
                Dim SQL As String = "Select * from SystemSettings Where Setting = 'TaskActions'"
                Adapter.SelectCommand = New OleDbCommand(SQL, Conn)
                Adapter.Fill(dt)
                If dt.Rows.Count > 0 Then
                    Return dt.Rows(0).Item("SettingValue").ToString
                Else
                    Return " "
                End If
            Catch ex As Exception
                Throw ex
            End Try
            Return ""
        End Get
        Set(ByVal value As String)
            Try
                Dim Conn As New OleDbConnection(gConnectionString)
                Dim Adapter As New OleDbDataAdapter
                Dim cmd As New OleDbCommand
                Dim dt As New DataTable
                Dim SQL As String = "Select * from SystemSettings Where Setting = 'TaskActions'"
                Adapter.SelectCommand = New OleDbCommand(SQL, Conn)
                Adapter.Fill(dt)
                Conn.Open()
                cmd.Connection = Conn
                If dt.Rows.Count > 0 Then
                    SQL = "UPDATE SystemSettings SET SettingValue = '" & value & "' WHERE [Setting]= 'TaskActions' "
                Else
                    SQL = "INSERT INTO SystemSettings ([Setting], SettingValue) VALUES ('TaskActions', '" & value & "')"
                End If

                cmd.CommandText = SQL
                cmd.ExecuteNonQuery()
                Conn.Close()
            Catch ex As Exception
                Throw ex
            End Try
        End Set
    End Property

    Property HideFutureDated() As Boolean
        Get
            Try
                Dim Conn As New OleDbConnection(gConnectionString)
                Dim Adapter As New OleDbDataAdapter
                Dim cmd As New OleDbCommand
                Dim dt As New DataTable
                Dim SQL As String = "Select * from SystemSettings Where Setting = 'HideFutureDated'"
                Adapter.SelectCommand = New OleDbCommand(SQL, Conn)
                Adapter.Fill(dt)
                If dt.Rows.Count > 0 Then
                    Return CBool(dt.Rows(0).Item("SettingValue"))
                Else
                    Return False
                End If

            Catch ex As Exception
                Throw ex
            End Try
            Return True
        End Get
        Set(ByVal value As Boolean)
            Try
                Dim Conn As New OleDbConnection(gConnectionString)
                Dim Adapter As New OleDbDataAdapter
                Dim cmd As New OleDbCommand
                Dim dt As New DataTable
                Dim SQL As String = "Select * from SystemSettings Where Setting = 'HideFutureDated'"
                Adapter.SelectCommand = New OleDbCommand(SQL, Conn)
                Adapter.Fill(dt)
                Conn.Open()
                cmd.Connection = Conn
                If dt.Rows.Count > 0 Then
                    SQL = "UPDATE SystemSettings SET SettingValue = '" & value & "' WHERE [Setting]= 'HideFutureDated' "
                Else
                    SQL = "INSERT INTO SystemSettings ([Setting], SettingValue) VALUES ('HideFutureDated', '" & value & "')"
                End If

                cmd.CommandText = SQL
                cmd.ExecuteNonQuery()
                Conn.Close()
            Catch ex As Exception
                Throw ex
            End Try
        End Set
    End Property


    Property StartingDate() As String
        Get
            Try
                Dim Conn As New OleDbConnection(gConnectionString)
                Dim Adapter As New OleDbDataAdapter
                Dim cmd As New OleDbCommand
                Dim dt As New DataTable
                Dim SQL As String = "Select * from SystemSettings Where Setting = 'StartingDate'"
                Adapter.SelectCommand = New OleDbCommand(SQL, Conn)
                Adapter.Fill(dt)
                If dt.Rows.Count > 0 Then
                    Return FormatDateTime(CDate(dt.Rows(0).Item("SettingValue")), DateFormat.ShortDate).ToString
                Else
                    Return Now().ToString
                End If

            Catch ex As Exception
                Throw ex
            End Try
            Return ""
        End Get
        Set(ByVal value As String)
            Try
                Dim Conn As New OleDbConnection(gConnectionString)
                Dim Adapter As New OleDbDataAdapter
                Dim cmd As New OleDbCommand
                Dim dt As New DataTable
                Dim SQL As String = "Select * from SystemSettings Where Setting = 'StartingDate'"
                Adapter.SelectCommand = New OleDbCommand(SQL, Conn)
                Adapter.Fill(dt)
                Conn.Open()
                cmd.Connection = Conn
                If dt.Rows.Count > 0 Then
                    SQL = "UPDATE SystemSettings SET SettingValue = '" & value & "' WHERE [Setting]= 'StartingDate' "
                Else
                    SQL = "INSERT INTO SystemSettings ([Setting], SettingValue) VALUES ('StartingDate', '" & value & "')"
                End If

                cmd.CommandText = SQL
                cmd.ExecuteNonQuery()
                Conn.Close()
            Catch ex As Exception
                Throw ex
            End Try
        End Set
    End Property
End Class
